#!/bin/bash

# Use first argument as ELF file, default to rtthread.elf
ELF_FILE="${1:-rtthread.elf}"

# OpenOCD configuration files
INTERFACE_CFG="/usr/local/share/openocd/scripts/interface/stlink-v2.cfg"
TARGET_CFG="/usr/local/share/openocd/scripts/target/stm32f4x.cfg"

# Print info in English
echo "Flashing firmware using OpenOCD: $ELF_FILE"
echo "Interface: CMSIS-DAP"
echo "Target MCU: STM32F4xx"

# Flash command
openocd \
    -f "$INTERFACE_CFG" \
    -f "$TARGET_CFG" \
    -c "init; program $ELF_FILE verify; reset run; exit"
